/*
 * ============================================================================
 *
 *       Filename:  to_lower.c
 *
 *    Description:  to lower
 *
 *        Version:  1.0
 *        Created:  05/30/13 14:40:01
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  jianxi sun (jianxi), ycsunjane@gmail.com
 *   Organization:  
 *
 * ============================================================================
 */
#include <stdio.h>
#include <stdint.h>

char _to_lower(char c)
{
	switch (c) {            
	case 'A': return 'a'; 	 
	case 'B': return 'b'; 	
	case 'C': return 'c'; 	
	case 'D': return 'd'; 	
	case 'E': return 'e'; 	
	case 'F': return 'f'; 	
	case 'G': return 'g'; 	
	case 'H': return 'h'; 	
	case 'I': return 'i'; 	
	case 'J': return 'j'; 	
	case 'K': return 'k'; 	
	case 'L': return 'l'; 	
	case 'M': return 'm'; 	
	case 'N': return 'n'; 	
	case 'O': return 'o'; 	
	case 'P': return 'p'; 	
	case 'Q': return 'q'; 	
	case 'R': return 'r'; 	
	case 'S': return 's'; 	
	case 'T': return 't'; 	
	case 'U': return 'u'; 	
	case 'V': return 'v'; 	
	case 'W': return 'w'; 	
	case 'X': return 'x'; 	
	case 'Y': return 'y'; 	
	case 'Z': return 'z';
	default: return c; 	
	} 			
}

#define del_blank(arg)  \
switch(arg) { 		\
case ' ': 		\
	url++; 		\
	continue; 	\
} 			\

to_lower(char *url)
{
	char *pre = url;
	while(*url != 0) {
		if(*url == '%') {
			*(url+2) = ((*(url+1) - '0') << 4) | (*(url+2) - '0');
			url += 2;
		}
		*pre = _to_lower(*url);
		del_blank(*pre);
		url++; pre++;
	}
	*pre = 0;
}

char string[1024];
int main()
{
	printf("Input a url:");
	scanf("%s",&string);
	to_lower((char *)&string);
	printf("%s\n",&string);

}
